﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Management/Manage.Master" Inherits="System.Web.Mvc.ViewPage<CSI.Directory.Core.Model.Menu>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    AddMenu
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  <script type="text/javascript">
      $(document).ready(function () {

          $("a").removeClass("current");
          $("#menus").addClass("current");
          var e = jQuery.Event("click");
          $("#menus").trigger(e);
          $("#add-menu").addClass("current");

      });
</script>
<div class="content-box">
 <div class="content-box-header" style="padding:5px 0px 0px 10px">
  <h3 >Add Menu</h3>
    <div class="clear">
            </div>
            </div>
   <div class="content-box-content" >
            <div class="tab-content default-tab" id="tab1">
              <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm("AddMenu", "Management", FormMethod.Post, new { name = "form1", id = "form1" }))
       {%>
    <%= Html.ValidationSummary(true)%>
    <fieldset>
       <%-- <legend >Fields</legend>--%>
        <%--<div style="clear:both; padding:3px"></div>--%>
        <div class="editor-label" style=" float:left; width:80px;">
            <%= Html.LabelFor(model => model.Order)%>
        </div>
        <div class="editor-field" style=" float:left; width:150px;" >
            <%= Html.TextBoxFor(model => model.Order)%>
            <%= Html.ValidationMessageFor(model => model.Order)%>
        </div>
        <div style="float:left; padding:0px 7px" class="red"> *</div>
        <div style="clear:both; padding:3px"></div>
        <div class="editor-label" style=" float:left; width:80px;">
            <%= Html.LabelFor(model => model.Name)%>
        </div>
        
        <div class="editor-field" style=" float:left; width:150px;" >
            <%= Html.TextBoxFor(model => model.Title)%>
            <%= Html.ValidationMessageFor(model => model.Title)%>
        </div>
        <div style="float:left; padding:0px 7px" class="red"> *</div>
        
         <div style="clear:both; padding:3px"></div>
        <p>
            <input type="button" value="Create" onclick="return DoAjaxSubmit(this);" class="button" style="text-decoration:none"/>
        </p>
        <div id="results"></div>
    </fieldset>
      <% } %>
        </div>
     <div>
        <%= Html.ActionLink("Back to List", "ShowMenu") %>
    </div>
        </div>
 </div>
                        
    <script type="text/javascript">
        function DoAjaxSubmit(btnClicked) {
            var form = $(btnClicked).parents('form');
                        if ($("#Title").val() == "" || $("#Order").val() == "") {
                            $("#results").html("Please complete all fields").addClass("red");
                            return false;
                        }
                        else {

            $("#results").html("");
            $.ajax({
                type: "POST",
                url: form.attr('action'), //'<%=ResolveUrl("~/register/go") %>',
                data: form.serialize(),
                error: function (xhr, status, error) {
                },
                success: function (response) {
                    if (response != null) {
                        if (!response.Successful) {
                            $("#results").html("An error occurred: " + response.Exception).addClass("red");
                            return false;
                        }
                        else {
                            $("#results").html("Menu added").addClass("green");
                            document.form1.reset();
                        }
                    }
                }
            });
           }
            return false;
        }
    </script>
</asp:Content>
